//
//  CZStatusCell.swift
//  CZWeibo
//
//  Created by 周振兰 on 16/5/20.
//  Copyright © 2016年 周振兰. All rights reserved.
//

import UIKit

//微博cell，既能显示原创微博，也能显示转发微博
class CZStatusCell: UITableViewCell {
    
    //cell要显示内容需要模型，控制器的tableView数据源给cell赋值模型
    var status:CZStatus?
        
        {
            didSet
                {
                    originalView.status = status
                     // cell给被转发的view赋值 被转发微博 模型
                    retweetView.reteetStatus = status?.retweeted_status
            }
    }
   

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
   
  //注册cell后系统创建cell的时候会调用这个构造函数
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        prepareUI()
    }
    
    func prepareUI()
    {
        backgroundColor = UIColor(white: 237/255.0, alpha: 1)
        //1.添加控件
        contentView.addSubview(originalView)
        contentView.addSubview(retweetView)
        contentView.addSubview(bottomView)
        
        //添加约束
        //原创view
        originalView.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(contentView).offset(10)
            make.leading.equalTo(contentView)
            make.trailing.equalTo(contentView)
         
        }
        
        //被转发的view
        retweetView.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(contentView)
            make.trailing.equalTo(contentView)
            make.top.equalTo(originalView.snp_bottom)
            //测试约束
//            make.height.equalTo(50)
        }
        
        
        //bottomView
        bottomView.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(contentView)
            make.top.equalTo(retweetView.snp_bottom)
            make.trailing.equalTo(contentView)
            make.height.equalTo(37)
        }
        
         // 根据cell的约束自动计算行高,系统是去获取contentView的高度作为cell的高度
        contentView.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(self)
            make.top.equalTo(self)
            make.trailing.equalTo(self)
            make.bottom.equalTo(bottomView)
        }
    }
    
    
    
//MARK:-懒加载
    ///原创view
    private lazy var originalView:CZStatusOriginalView = CZStatusOriginalView()
    
    ///被转发view
    
    private lazy var retweetView:CZStatusRetweetView = CZStatusRetweetView()
    ///bottomView
    private lazy var bottomView :CZStatusBottomView = CZStatusBottomView()
    
}
